// 药房管理
<template comments>
  <div class="pharmacy">
    <TopManu :stprageStatus="8" @handcreate="handcreate" @handleDerive='printDerive'></TopManu>
  
    <div class="search">
      <div class="s1">
        <el-input
          v-model="params.keyword"
          placeholder="请输入名称"
        ></el-input>
         <!-- <el-input
         type='number'
          v-model="params.useful_day"
          placeholder="保证期小于"
        >
         <template slot="append">天</template>
        </el-input> -->
        <el-button @click="searchB()" class="butB_Sel">查询</el-button>
        <el-button @click="resetSearchB()"  class="butB_Reset">重置</el-button>
      </div>
      <div class="selectBai">
            <div>
          <el-select v-model="params.store_id" placeholder="药库" @change="searchB">
            <el-option
              v-for="item in  KuFangList" 
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
           <div>
          <el-select v-model="params.species_id" placeholder="药品种类" @change="searchB">
            <el-option
              v-for="item in  speciesList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div>
          <el-select v-model="params.category_id" placeholder="药品分类" @change="searchB">
            <el-option
              v-for="item in  drugList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
   <div>
          <el-select v-model="params.form_of_drug" placeholder="剂形" @change="searchB">
            <el-option
              v-for="item in  form_of_drugList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        
       </div>
    </div>

    <div class="tablesB">
      <el-table  highlight-current-row @current-change="handleCurrentChange"  v-loading="params.loading" :data="data" border >
        <el-table-column type="index" width="70" label="序号">
        </el-table-column>
        <template v-for="(item, index) in $baseBai['drugStorage']['list']">

             <el-table-column :width="item.width" v-if="item.prop == 'service_for'" :prop="item.prop" :label="item.label" :key="index">
                        <template slot-scope="scope">
                            <div v-if="scope.row.service_for">{{ $baseBai['drugStorage']['service_for'][scope.row.service_for-1].label }}</div>
                        </template>
              </el-table-column>
         
             <el-table-column :width="item.width" v-else-if="item.prop == 'status'" :prop="item.prop" :label="item.label" :key="index">
                        <template slot-scope="scope">
                            <div v-if="scope.row.status">{{ $baseBai['drugStorage']['status'][scope.row.status-1].label }}</div>
                        </template>
              </el-table-column>
            <el-table-column  v-else :width="item.width" :prop="item.prop" :label="item.label" :key="index+item"> </el-table-column>
           </template>
           <el-table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <div>
              <el-button
                size="mini"
                
                class="butB_Det"
                @click="handleEdit(scope.$index, scope.row, 1)"
                >详情</el-button
              >
            
            </div>
          </template>
        </el-table-column>
      
      </el-table>
        <div>
           <el-pagination
           class="fenye"
            :background="true"
            :current-page="params.page"
            :page-size="params.limit"
            layout="prev, pager, next"
            @current-change="handlePagination"
            :total="params.pageCount">
            </el-pagination>
      </div>
    </div>


      <el-dialog
        :title="dialogTitle"
        :destroy-on-close	="true"
        :visible.sync="Detail_Show"
        width="30%"
        :before-close="()=>{this.Detail_Show=!this.Detail_Show}">
             <Detail :dialogTitle='dialogTitle'     :thatF="this"></Detail>
      
      </el-dialog>
  </div>
</template>

<script>
let t;
import Detail from './common/detail'
import TopManu from "@/components/TopMenu";
import { mapState,mapActions } from "vuex";
import {http} from "@/utils/server.js"
import {exportStoreNum} from "@/api/account.js"
// getDict_dataKuFangList
export default {
  name:"drugStorage",
  data() {
    return {
      Detail_Show:false,
      tableTitle: [],
      dialogTitle:'',
      params: {
        loading:false, 
        tabIndex: "1",
        page:1,
        limit:10,
        form_of_drug:'',
        species_id: "",
        store_id:'',
        category_id: "",
      },

     selectItem:{},
      data: [],
      store_house:'',
    };
  },
  components: {
    TopManu,
    Detail,
  },
 
  mounted() {
    t = this;
         if(t.KuFangList.length==0){
        t['dictBai/getDict_dataKuFangList']({})
    }

        if(t.drugList.length==0){
       t['dictBai/getDrugCategoryIndex']({})
            }
            if(t.speciesList.length==0){
            t['dictBai/getDrugDrugSpeciesIndex']({})
            }
             if(t.form_of_drugList.length==0){
            t['dictBai/getdosageGetList']({})
            }

  
      t.getList()
     
   
  },
    computed: {
    ...mapState({
      dataDetail: (state) => state.storage.dataDetail,
       KuFangList: state => state.dictBai.KuFangList,
        drugList: state => state.dictBai.drugList,
      speciesList: state => state.dictBai.speciesList,
      form_of_drugList:state => state.dictBai.form_of_drugList,
    }),
  },
  
  methods: {
     ...mapActions([
        
        'dictBai/getDict_dataKuFangList',
        'dictBai/getDrugCategoryIndex',
        'dictBai/getDrugDrugSpeciesIndex',
        'dictBai/getdosageGetList',
         'storage/getdrug_storedDugNumShow',
         'storage/emptyData',

       
			]),

       handleCurrentChange(item){
        console.log("item1",item)
        this.selectItem=item;
      },
     resetSearchB(){
       this.params={
        loading:false, 
        tabIndex: "1",
        page:1,
        limit:10,
        form_of_drug:'',
        species_id: "",
        store_id:'',
        category_id: "",
      } 
      this.getList()
     },
    
       handleEdit(...item){
       
            console.log("item",item)
            
               this.store_house= item[1].store_house
                 console.log(  t.store_house)
                t['storage/getdrug_storedDugNumShow']({drug_id:item[1].id}).then(res=>{
                if(res.code==200)
                {t.Detail_Show=!t.Detail_Show;
              
                console.log("res",res)
                t.dialogTitle='详情信息';
                }
               })
               
          
      },
      handcreate(num){
          let url='';
          console.log("num",num)
            switch (num) {
            case 1:
                  url='purchaseApply'
              break;
            case 2:
               url='purchasePlan'
                break;
             case 3:
               url='enterManage'
                break;
             case 4:
               url='outManage'
                break;
             case 5:
               url='drugCollar'
                break;
             case 6:
               url='drugRetreat'
                break;
             case 7:
               url='drugInspect'
                break;
             case 'storeUpload':
                  
                   if(!t.selectItem.id){
                     return  t.$message.error("请些选中药品信息")
                   }
                   
                    let d={
                      drug_id:t.selectItem.id
                    }
                      return  this['_API'].getdrug_storedStoreUpload(d).then(res=>{
                         
                                  if(res.code==200){
                                    
                                       t.$message(res.message)
                                          
                                        
                                  }
                        })
                   
                break;
            default:
              break;
            }
         this.$router.push({name:url})
      },
  
  
    
    searchB() {
     
      t.params.page=1;
      t.getList()
    },

 
     handlePagination(e){
       
         t.params.page=e;
        t.getList()
        
    },
    getList(){
     


      let d={
       
        limit:t.params.limit,
        page:t.params.page,
        keyword:t.params.keyword,
         species_id:t.params.species_id,
         category_id:this.params.category_id,
         form_of_drug:t.params.form_of_drug,
         store_id:t.params.store_id,
      }
      t.data=[];
       this.params.loading=true;
      this['_API'].getdrug_storeDrugIndex(d).then(res=>{
         this.params.loading=false;
                 if(res.code==200){
                   
                     
                        this.data=res.data.list;
                        this.params.pageCount =res.data.count;
                       
                 }
      })
      
    },
       printDerive(){
      exportStoreNum()
      .then(res=>{
        window.open(http + '/' +res.data.file_url);
      }) 
      .catch(e=>{
        this.$message({
          message:e.message,
          type: 'error'
        });
      })
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/ .el-tabs__nav {
  
  .el-tabs__item {
    border-bottom: 1px solid #e4e7ed;
  }
  .is-active {
    color: #02bf6b;
  }
  .el-tabs__item:hover {
    color: #02bf6b;
  }
}
.search {
  border: 1px solid #f2f2f2;
  margin: 10px 2%;
  padding: 20px;
  border-radius: 10px;
  .s1 {
       margin-bottom: 20px;
    width: 405px;
    display: flex;
    .el-input{
      margin-right: 10px;
    }
    button {
      margin-left: 20px;
     
      
      color: white;
    }
  }
  .selectBai {
    display: flex;
    > div {
      margin-right: 10px;
    }
  }
}

.tableMore {
  /deep/ .el-button--primary {
    color: black;
    background-color: initial;
    border-color: #e2e2e2;
  }
}
.tablesB,.tabsB{margin: 20px 2% 0;}

  .fenye{
    text-align: right;
    margin-top: 20px;   
    
  }
  /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{
      background-color: #02bf6b;
  }

  
  /deep/ .el-dialog__body {
  height: 70vh;
  overflow: scroll;
}
/deep/ .el-dialog{
        width: 80% !important;
  }
  /deep/ .el-table__body tr.current-row>td{
  background-color: #d7ede3;
}
</style>